package com.lb.shopguide.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.lb.shopguide.R;
import com.lb.shopguide.config.UserConfigManager;
import com.lb.shopguide.constants.AppConstant;
import com.lb.shopguide.entity.goods.GoodsInListBean;
import com.lb.shopguide.im.callback.GoodsCallback;
import com.lb.shopguide.base.BaseActivity;
import com.lb.shopguide.ui.fragment.guide.order.FragmentOrderList;
import com.lb.shopguide.ui.fragment.guide.goods.FragmentSelectGoods;

import java.util.List;

import me.yokeyword.fragmentation.anim.FragmentAnimator;

/**
 * Created by kang on 2017/6/7.
 */

public class MessageDetailChooseActivity extends BaseActivity {

    private static GoodsCallback mCallback;
    private int mStatus;
    private String accId;
    private UserConfigManager mUserConfigManager;

    public static void start(Activity activity, GoodsCallback callback, String accId, int status) {
        Intent intent = new Intent();
        mCallback = callback;
        Bundle bundle = new Bundle();
        bundle.putInt(AppConstant.INTENT_KEY_MESSAGE_DETAIL_STATUS, status);
        bundle.putString(AppConstant.PRE_KEY_ACCID, accId);
        intent.setClass(activity, MessageDetailChooseActivity.class);
        intent.putExtras(bundle);
        activity.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_message_detail_choose);

        mUserConfigManager = UserConfigManager.getInstance(this);
        Bundle bundle = getIntent().getExtras();
        if (bundle.containsKey(AppConstant.INTENT_KEY_MESSAGE_DETAIL_STATUS)) {
            mStatus = bundle.getInt(AppConstant.INTENT_KEY_MESSAGE_DETAIL_STATUS);
        }
        if (bundle.containsKey(AppConstant.PRE_KEY_ACCID)) {
            accId = bundle.getString(AppConstant.PRE_KEY_ACCID);
        }
        if (savedInstanceState == null) {
            if (mStatus == AppConstant.CONSTANT_MESSAGE_CHOOSE_GOODS) {
                loadRootFragment(R.id.fl_container, FragmentSelectGoods.newInstance(AppConstant.GOODS_SELECT_IN_CHAT));
            } else if (mStatus == AppConstant.CONSTANT_MESSAGE_LOOK_ORDER) {
                loadRootFragment(R.id.fl_container, FragmentOrderList.newInstance(accId, true));
            }

        }
    }

    public void onGoodsSelected(List<GoodsInListBean> list) {
        if (mCallback != null) {
            mCallback.onGoodsSelected(list);
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    public FragmentAnimator onCreateFragmentAnimator() {
        return super.onCreateFragmentAnimator();
    }


    @Override
    public void onBackPressedSupport() {
        if (getSupportFragmentManager().getBackStackEntryCount() > 1) {
            pop();
        } else {
            finish();
        }
    }
}
